package com.itcast.googleplay.adapter;

import java.util.List;

import com.itcast.googleplay.holder.BaseHolder;
import com.itcast.googleplay.utils.UIUtils;
import com.nineoldandroids.view.ViewHelper;
import com.nineoldandroids.view.ViewPropertyAnimator;

import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.BaseAdapter;

public  abstract class MyBaseAdapter<T> extends BaseAdapter{
	private List<T> list;
	private BaseHolder baseHolder;
	public int currentPosition;
	
	public MyBaseAdapter(List<T> list) {
		this.list = list;
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public T getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public  View getView(int position, View convertView, ViewGroup parent){
		currentPosition = position;
		if(convertView == null){
			baseHolder = getHolder();
		}else{
			baseHolder = (BaseHolder) convertView.getTag();
		}
		baseHolder.setData(list.get(position));
		View view = baseHolder.getConvertView();
		ViewHelper.setScaleX(view, 0.5f);
		ViewHelper.setScaleY(view, 0.5f);
		
		ViewPropertyAnimator.animate(view).scaleX(1.0f).setDuration(350)
		.setInterpolator(new OvershootInterpolator())
		.start();
		ViewPropertyAnimator.animate(view).scaleY(1.0f).setDuration(350)
		.setInterpolator(new OvershootInterpolator())
		.start();
		
		return baseHolder.getConvertView();
	}
	
	public abstract BaseHolder<T> getHolder();
}
